﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Booking.Resources;
using Booking.WPServiceData;


namespace Booking
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        private void txtMonAn_TextChanged(object sender, TextChangedEventArgs e)
        {
            search();   
        }

        private void txtDiaChi_TextChanged(object sender, TextChangedEventArgs e)
        {
        }

        public void search()
        {
            String address = "";
            String nameMenu = txtMonAn.Text;
            if (nameMenu.Equals("Tên món ăn"))
            {
                nameMenu = "";
            }

            ServiceSoapClient service = new ServiceSoapClient();
            service.SearchMenuByAddressAndNameCompleted += new EventHandler<SearchMenuByAddressAndNameCompletedEventArgs>(fillSearchSupplier);

            service.SearchMenuByAddressAndNameAsync(nameMenu, address);
        
        }
        public void fillSearchSupplier(object sender, SearchMenuByAddressAndNameCompletedEventArgs e) 
        {
            var data = new List<menu>(e.Result);
            foreach (menu _menu in data)
            {
                _menu.images = lib.DefinesClass.ipService + _menu.images;
            }
            if (e.Result != null)
            {
                lbltenNhaHang.ItemsSource = e.Result;
            }
         }

        private void lbltenNhaHang_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            menu selectItem =(menu)  lbltenNhaHang.SelectedItem;
            NavigationService.Navigate(new Uri("/Chitiet.xaml?id=" + selectItem.id, UriKind.Relative));
           //   MessageBox.Show(selectItem.name);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/PivotPage1.xaml", UriKind.Relative));
        }

       

        private void txtMonAn_MouseEnter_1(object sender, System.Windows.Input.MouseEventArgs e)
        {
            txtMonAn.Text = "";
        }

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}